package com.nuoniu.sibanyun.service.erp.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.erp.ErpProjectTask;
import com.nuoniu.sibanyun.mapper.erp.ErpProjectTaskMapper;
import com.nuoniu.sibanyun.service.erp.IErpProjectTaskService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 项目任务 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-25
 */
@Service
public class ErpProjectTaskServiceImpl extends ServiceImpl<ErpProjectTaskMapper, ErpProjectTask> implements IErpProjectTaskService {

    @Override
    public List<ErpProjectTask> getList(Integer projectId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("project_id", projectId);
        return list(wrapper);
    }

    @Override
    public void saveTask(ErpProjectTask projectTask) {
        UserInfo userInfo = UserThreadLocal.get();
        if(projectTask.getId() == null) {
            projectTask.setCreateUserId(userInfo.getUserId());
            projectTask.setCreateUserName(userInfo.getRealName());
        } else {
            projectTask.setUpdateDate(LocalDateTime.now());
            projectTask.setUpdateUserId(userInfo.getUserId());
            projectTask.setUpdateUserName(userInfo.getRealName());
        }
        this.saveOrUpdate(projectTask);
    }
}
